import {getData} from '../services/dashboard';

export default {
  namespace: 'dashboard',

  state: {
    data: [],
  },

  effects: {
    * getData(_, {call, put}) {
      const result = yield call(getData);
      if (result && result.code === 0) {
        yield put({
          type: 'saveData',
          payload: result.data,
        });
      }
    },
  },

  reducers: {
    saveData(state, {payload}) {
      return {
        ...state,
        data: payload,
      };
    },
  },
};
